package com.chatcompetition.controller;


import com.chatcompetition.domain.dto.FeedbackDTO;
import com.chatcompetition.domain.entity.Feedback;
import com.chatcompetition.result.Result;
import com.chatcompetition.service.FeedbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;


    /**
     * 添加反馈
     */
    @PostMapping("")
    public Result addFeedback(@RequestBody FeedbackDTO feedbackDTO) {
        log.info("反馈内容：{}", feedbackDTO);
        feedbackService.addFeedback(feedbackDTO);
        return Result.success();
    }

    /**
     * 查询所有反馈
     */
    @GetMapping
    public Result<List<Feedback>> getAllFeedback() {
        List<Feedback> feedbackList = feedbackService.list();
        return Result.success(feedbackList);
    }
    /**
     * 更新反馈
     */
    @PutMapping("/{id}")
    public Result updateFeedback(@PathVariable Long id, @RequestBody Feedback feedback) {
        feedback.setId(id);
        feedbackService.updateById(feedback);
        return Result.success();
    }

    /**
     * 删除反馈
     */
    @DeleteMapping("/{id}")
    public Result deleteFeedback(@PathVariable Long id) {
        feedbackService.removeById(id);
        return Result.success();
    }
}
